function [x,output]=solveall_tol_shareimmediate(xguess,index,ew,waut,bind,nobind,tol,gammasub);

global gammagrid table grid states ewdev S Sdev agent statedev P wdev
global beta Y rho 
objval = [];
output=[];
options = optimoptions(@fsolve,'Algorithm','trust-region-reflective','Display','iter','FunctionTolerance',tol);
[x,fval,exitflag]=fsolve(@objfun,xguess,options);
output(6)=exitflag;
function f = objfun(x);
i=index(1);
j=index(2);
d=index(3);
k=index(4);         %%%coalition of constrained agents
h=index(5);         %%%no of constrained agents
consu(1:agent-1) = x(1:agent-1);
consu(agent)=Y(j)-sum(x(1:agent-1));
method=1;

if method==1
wint=interpolation_4agents(ew, index,x./Y(j));
else
wint=chebyshevinterpolation(ew,index, x/Y(j),coeff,agent);
end  
for g=1:agent
output(g)=utility(rho,consu(g))+beta*wint(g);
end

for r=1:length(nobind)
f(r) = gammagrid(i,nobind(end))/gammagrid(i,nobind(r))-consu(nobind(end))/consu(nobind(r));
end
for r=1:length(bind)
if h>1
f(agent+r) = wdev(d,statedev(j,k,h),r,h) - output(bind(r));
else
f(agent+1)=(utility(rho,S(j,bind(r)))+beta*P(j,:)*waut(:,bind(r))-output(bind(r)));
end
end
end
x;
end